package com.alumni_circle.mapper.gossip;

import com.alumni_circle.entity.gossip.Comments;
import com.alumni_circle.entity.gossip.VO.CommentsViewVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 龙小虬
 * @since 2020-07-06 22:11
 */
public interface CommentsMapper extends BaseMapper<Comments> {

//    @Select("select comments.id,comments.content,comments.praise,comments.create_time,user.icon,user.name\n" +
//            "FROM user,comments,user_comments,gossip_comments\n" +
//            "WHERE user.id = user_comments.user_id and user_comments.comments_id = comments.id \n" +
//            "and comments.state='0'  and  gossip_comments.comments_id = comments.id and gossip_comments.gossip_id = #{gossipId}\n" +
//            "ORDER BY create_time DESC")
//    List<CommentsViewVO> selectListComments(@Param("gossipId") String gossipId);

    @Select("SELECT b.*,a.`like`\n" +
            "FROM like_comments_sum a RIGHT JOIN (\n" +
            "select comments.id,comments.content,comments.praise,comments.create_time,user.icon,user.name\n" +
            "FROM user,comments,user_comments,gossip_comments\n" +
            "WHERE user.id = user_comments.user_id and user_comments.comments_id = comments.id \n" +
            "and comments.state='0'  and  gossip_comments.comments_id = comments.id and gossip_comments.gossip_id = #{gossipId}\n" +
            ") b on b.id = a.comments_id AND a.user_id = #{id} ORDER BY create_time DESC")
    List<CommentsViewVO> selectListComments(@Param("gossipId") String gossipId,@Param("id")String id);

    @Select("update comments set praise=praise+1 where id = #{id}\n")
    void updateCur(@Param("id")String id);
}
